//
//  HealthDataRequest.m
//  Cycling
//
//  Created by CSS on 4/21/23.
//

#import "HealthDataRequest.h"

#import "BaseBodyModel.h"

#import "Cycling-Swift.h"

@implementation HealthDataRequest

+ (void)requestHealthDateRangeWithComplete:(void(^)(NSDate *fromDate, NSDate *endDate))complete
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@", BaseUrl, Health_API_Config];
    [self basePOST:urlString cache:NO autoHideLoading:NO parms:@{} result:^(id resultObject, NSError *error) {
        if(!resultObject) {
            return;
        }
        BaseBodyModel *model = [BaseBodyModel yy_modelWithJSON:resultObject];
        if (model.code == 1) {
            NSInteger day = [[model.data valueForKey:@"day"] integerValue];
            NSDate *endDate = [NSDate date];
            NSDate *fromDate = [[endDate dateMoveByDay:-day] moveToBeginOfTheDate];
            [endDate postHealthDataToServerFromDate:fromDate endDate:endDate];
            if(complete) {
                complete(fromDate, endDate);
            }
        }
    }];
}

+ (void)addHealthDataToServerWithParams:(NSString *)jsonString
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@", BaseUrl, Health_API_AddHealthData];
    [self basePOST:urlString cache:NO autoHideLoading:NO parms:@{@"json" : jsonString} result:^(id  _Nullable resultObject, NSError * _Nullable error) {
        
    }];
}

@end
